package io.xxx.omni.oss.custom

import com.google.gson.JsonObject
import io.xxx.omni.oss.common.toJsonString
import io.xxx.omni.oss.common.toLocalDateTime
import io.xxx.omni.oss.domain.Document
import io.xxx.omni.oss.domain.DocumentType

@Suppress("unused")
class YjTradeSynchronizer : YjSynchronizer() {

    override val documentType = DocumentType.TRADE

    override val method = "pop.order.list.get"

    override fun getCount(context: Context, response: JsonObject): Int {
        return response.get("total_results").asInt
    }

    override fun buildDocuments(context: Context, response: JsonObject): List<Document> {
        return response
            .getAsJsonArray("lists")
            .map {
                it as JsonObject
                Document(
                    it["order_id"].asString,
                    it["status"].asString,
                    it.toJsonString(),
                    it["create_time"].asString.toLocalDateTime(),
                    it["modify_time"].asString.toLocalDateTime(),
                )
            }
    }
}